<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>回顾Object.defineproperty()方法</title>
    <script src="../commonjs/vue.js"></script>
</head>
<body>
    <script type="text/javascript">
        let num  = 18
        let person = {
            name:'张三',
            sex:'男'
        }
        Object.defineProperty(person,'age',{
            // value:18,
            // enumerable:true, //可枚举：默认false，设置为true后该属性可被枚举
            // writable:true, //可编辑：默认false，设置为true后该属性值可被修改
            // configurable:true, //可删除：默认false，设置为true后该属性可被删除
            //当调用person.age时，get方法被调用
            get(){
                console.log("有人读取age属性了！")
                return num
            },
            //当有人修改age属性时调用set,且会收到修改的具体值
            set(value){
                console.log("有人修改了age，值是：",value)
                num = value
            }
        })
        for (const key in person) {
            console.log('@',key)
        }
        console.log(person)
    </script>
</body>
</html>